from core.config import CACHE_CONF
from TDhelper.cache.webCache.webCacheFactory import webCacheFactory
from TDhelper.db.mongodb.objectId import objectId
WEB_CACHE= webCacheFactory(conf=CACHE_CONF)

# cache model
class Token(objectId):
    
    def __init__(self,**kwargs):
        super(Token,self).__init__()
        
    @property
    def token(self):
        if 'token' in self.model:
            return self.model['token']
        else:
            raise Exception("NOT FOUND 'token' in model.")
    
    @token.setter
    def token(self,v):
        if 'token' in self.model:
            self.model['token']=v
        else:
            raise Exception("NOT FOUND 'token' in model.")

    @property
    def expire(self):
        if "expire" in self.model:
            return self.model['expire']
        else:
            raise Exception("NOT FOUND 'expire' in model.")

    @expire.setter
    def expire(self,v):
        if 'expire' in self.model:
            self.model['token']=v
        else:
            raise Exception("NOT FOUND 'expire' in model.")
        
    @property
    def sys_key(self):
        if "sys_key" in self.model:
            return self.model["sys_key"]
        else:
            raise Exception("NOT FOUND 'sys_key' in model.")
    
    @sys_key.setter
    def sys_key(self,v):
        if 'sys_key' in self.model:
            self.model["sys_key"]=v
        else:
            raise Exception("NOT FOUND 'sys_key' in model.")
    
    @property
    def event(self):
        if "event" in self.model:
            return self.model["event"]
        else:
            raise Exception("NOT FOUND 'event' in model.")
    
    @event.setter
    def event(self,v):
        if 'event' in self.model:
            self.model["event"]=v
        else:
            raise Exception("NOT FOUND 'event' in model.")
     
    @property
    def union_field(self):
        if "union_field" in self.model:
            return self.model["union_field"]
        else:
            raise Exception("NOT FOUND 'field' in model.")
        
    @union_field.setter
    def union_field(self,v):
        if "union_field" in self.model:
            self.model["union_field"]= v
        else:
            raise Exception("NOT FOUND 'field' in model.")
                
    @property
    def remote_ip(self):
        if "remote_ip" in self.model:
            return self.model["remote_ip"]
        else:
            raise Exception("NOT FOUND 'remote_ip' in model.")
        
    @remote_ip.setter
    def remote_ip(self,v):
        if 'remote_ip' in self.model:
            self.model['remote_ip']=v
        else:
            raise Exception("NOT FOUND 'remote_ip' in model.")

    @property
    def is_use(self):
        if "is_use" in self.model:
            return self.model["is_use"]
        else:
            raise Exception("NOT FOUND 'is_use' in model.")
        
    @is_use.setter
    def is_use(self,v):
        if 'is_use' in self.model:
            self.model['is_use']=v
        else:
            raise Exception("NOT FOUND 'is_use' in model.")  

    @property
    def use_once(self):
        if "use_once" in self.model:
            return self.model["use_once"]
        else:
            raise Exception("NOT FOUND 'use_once' in model.")
        
    @use_once.setter
    def use_once(self,v):
        if 'use_once' in self.model:
            self.model['use_once']=v
        else:
            raise Exception("NOT FOUND 'use_once' in model.")

WEB_CACHE.addCollect("token",Token)